package com.badu.app.api;

import javax.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.badu.app.domain.AppUser;
import com.badu.app.service.IAppUserService;
import com.badu.common.utils.R;

@Validated
@RestController
@RequestMapping("api/app/user")
public class AppUserApi {

	@Autowired
	private IAppUserService appUserService;
	
	@GetMapping("queryAppUser")
	public R queryUser(@NotBlank(message = "openId不能为空")String openId) {
		return R.ok().put("data", appUserService.getAppUserByOpenId(openId));
	}
	
	@PostMapping("addAppUser")
	public R addAppUser(@NotBlank(message = "openId不能为空")String openId,AppUser  appUser) {
		appUser.setOpenId(openId);
		return R.ok().put("data", appUserService.addAppUser(appUser));
	}
	
	@PostMapping("updateAppUser")
	public R updateAppUser(AppUser  appUser) {
		return R.ok().put("data", appUserService.updateAppUser(appUser));
	}
}
